#ifndef SC_CLIENT_H_INCLUDED
#define SC_CLIENT_H_INCLUDED

#include "gl/glwindow.h"
#include "entity.h"
#include "player.h"
#include "car.h"
#include "map_mesh.h"
#include "sc_messageinfo.h"
#include "physics/be_physics_system.h"
#include "graphics/be_graphics_system.h"
#include "graphics/sc_graphics.h"
#include "utils/joystick.h"
#include "gui/canvas.h"
#include "../gui/speedo.h"

// FIXME make generic message, add type to cm
// like m_joinedPlayers m_disapprovedPlayers m_approvedPlayers

class ScClient
{
	public:
		ScClient();
		virtual ~ScClient();

		void	draw();
		void	process( float timeDelta );
		boost::shared_ptr<Player> findPlayer(unsigned int id);
		void	pushIncomingmessage( const string& message ) { m_messages_in.push_back(message); }
		void	pushOutgoingmessage( const string& message ) { m_messages_out.push_back(message); }

		// PHYSICS
		BePhysicsSystem m_physicsSystem;
		boost::shared_ptr<btDynamicsWorld> m_dynamicsWorld;

		typedef std::vector< boost::shared_ptr<Entity> > Entities;
		typedef std::vector< boost::shared_ptr<Player> > Players;

		Entities		m_entities;
		Players			m_players;

		void newLogMessage(const string& msg);

		boost::shared_ptr<Player> me;

		vector<string>	m_messages_in;
		vector<string>	m_messages_out;

		BeCameraPerspective	m_camera;

		boost::scoped_ptr<Canvas>	m_canvas;
//  		Canvas m_canvas;

	private:

		void mapChange( const std::string& name );

		void playerConnect( boost::shared_ptr<Player> player, const unsigned int id );
		void playerDisconnect( boost::shared_ptr<Player> player );

		void playerJoin( boost::shared_ptr<Player> player );
		void playerUnjoin( boost::shared_ptr<Player> player );
		void playerFinish( boost::shared_ptr<Player> player, const std::string& msg );

		void		parseIncomingMessages();
		boost::shared_ptr<Map>	m_map;

		const unsigned int*		setting_drawscene;
		const unsigned int*		setting_follow;
		const unsigned int*		setting_camera_follow;

		// GL WINDOW
			GLWindow		glwindow;	

		// GRAPHICS
			BeGraphicsSystem m_graphicsSystem;
			boost::scoped_ptr<ScGraphics> m_graphics;
			BeCameraPerspective 	m_cameraFollow;
			BeSceneNode		m_sceneNodeCamera;
			BeSceneNode		m_sceneNodeCameraFollow;
		

		// SPEEDO
			Speedo*		speedo;
	
		// JOYSTICK
			boost::scoped_ptr<Joystick>		m_joystick;

		// UTILS
			Settings*		settings;
			BeParser		parseH;
};

#endif
